package com.hzw.code.security.model;

import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.Date;

/**
 * 自定义Spring Security用户详情类
 */
@Data
public class CustomUserDetails implements UserDetails {

    /**
     * 用户编号
     */
    @TableId
    private String userId;

    /**
     * 登录账号
     */
    private String realName;

    /**
     * 密码
     */
    private String userPass;

    /**
     * 用户名称
     */
    private String userName;

    /**
     * 手机号码
     */
    private String userPhone;

    /**
     * 邮箱
     */
    private String userEmail;

    /**
     * 数据状态：1启用；2禁用
     */
    private Integer userStatus;

    /**
     * 创建时间
     */
    private Date createTime;

    /**
     * 用户头像
     */
    private String headImg;

    /**
     * 创建人
     */
    private String createUserId;

    /**
     * 修改时间
     */
    private Date modifyTime;

    /**
     * 修改人
     */
    private String modifyUserId;

    /**
     * 备注
     */
    private String remark;

    /**
     * 用户uuid随机串
     */
    private String uuidKey;

    /**
     * 用户权限
     */
	private Collection<? extends GrantedAuthority> authorities;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return this.authorities;
    }

    public void setAuthorities(Collection<? extends GrantedAuthority> authorities) {
        this.authorities = authorities;
    }

    @Override
    public String getPassword() {
        return this.userPass;
    }

    @Override
    public String getUsername() {
        return this.userName;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return userStatus == 1;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return userStatus == 1;
    }

}
